*** Stata 14.1 reproduction code for Mader & Schoen. 2017. Ideological voting in context: The case of Germany during the Merkel era

*** This code (1) cleans media content data.

*** Data set used:
*** Long-Term GLES Media Agenda Analysis (ZA5323, version 2.0)
*** Note: An updated, (as of 9/12/2016) preliminary version of ZA5323, version 2.0, was used; 
***		  we thank the GLES for sharing this data with us.


*****************************************************************************************************************
*****************************************************************************************************************
													* (1) Clean media content data
*****************************************************************************************************************
*****************************************************************************************************************

	set more off

*** Define directory with data sets
	cd "C:\Users\m.mader\Google Drive\Forschung\Mader_Schoen_2017_GLES_Book\Daten"

*** Load GLES Media Agenda Analysis data set
	use ZA5323_Vorläufig.dta, clear

*** Core time period of analysis (four weeks before survey starts)
	fre tk_alt
	gen track = tk_alt
	recode track (0 = .)
	tab track tk_alt
	
	*Delete observations which are not in core time period of analysis
	drop if track == .
	
*** Dummy if no of words > 100
	gen nwords100 = 0
	replace nwords100 = 1 if nwords > 100
	fre nwords100

	
*************************************************************************************************************************************************************************************************************************************
*** Policy issues 

*** Welfare issues - retirement and health care
	*Retirement (CAT3640)
	*Health care (CAT3660) 
	gen retirementhealth_count = CAT3640 + CAT3660

	gen retirementhealth = 0
	replace retirementhealth = 1 if retirementhealth_count >= 2
	replace retirementhealth = . if nwords100 == 0
	
	graph bar retirementhealth, over(track) blabel(total, format(%9.2f))
	window manage close graph
	 
	tab track retirementhealth, row

	
**************************************************************************************************************************************************
*** Partisan actors
	* Parties in the Bundestag (SPD, Grüne, Linke, CDU/CSU, FDP) plus AfD
	* Politicians (Federal level: Chancellor, ministers, Leaders of parliamentary factions, chairman of a party, chancellor candidate Steinbrück)
	
	*Left political actors (SPD, Grünen, Linke + politicians of these parties)
		gen left_actx = CAT0110 + CAT0120 + CAT0125 + CAT0350 + CAT0222 + CAT0223 + CAT0224 + CAT0225 + CAT0227 + CAT0229 + CAT0271 + CAT0272 + CAT0273 + CAT0276 + CAT0277 + CAT0278 + CAT0291 + CAT0293 + ///
			CAT0294 + CAT0295 + CAT0296 + CAT0297 + CAT0298 + CAT0299 + CAT0300 + CAT0301 + CAT0350


	*Drop articles with < 3 codes and less than 100 words
		gen left_act = 0
		replace left_act = 1 if left_actx >= 2
		replace retirementhealth = . if nwords100 == 0

		tab track left_act, row
		
				
	*Right political actors (CDU/CSU, FDP, AfD + politicians of these parties)

	gen right_actx = CAT0100 + CAT0105 + CAT0115 + CAT0155 + CAT0201 + CAT0202 + CAT0203 + CAT0204 + CAT0205 + CAT0206 + CAT0207 + CAT0208 + CAT0209 + CAT0210 + CAT0211 + CAT0212 + CAT0213 + CAT0214 + CAT0215 + ///
		CAT0216 + CAT0217 + CAT0218 + CAT0219 + CAT0220 + CAT0221 + CAT0226 + CAT0228 + CAT0230 + CAT0270 + CAT0274 + CAT0275 + CAT0290 + CAT0292 + CAT0306 + CAT0307 + CAT0308

		
	*Drop articles with < 3 codes and less than 100 words
		gen right_act = 0
		replace right_act = 1 if right_actx >= 2
		replace retirementhealth = . if nwords100 == 0
	
		tab track right_act, row

	
	*Left OR Right actors
	gen act = 0
	replace act = 1 if left_act == 1 | right_act == 1
	
	graph bar act, over(track) blabel(total, format(%9.2f))
	window manage close graph
	
	
******************************************************************
* Combine health and retirement issue salience and actor salience

	*Health and retirement policies
	gen retirementhealth_act = 0
	replace retirementhealth_act = 1 if retirementhealth == 1 & act == 1
	
	graph bar retirementhealth_act, over(track) blabel(total, format(%9.2f))
	window manage close graph

******************************************************************
**** Collapse and save media data
	collapse (mean)   retirementhealth_perc = retirementhealth ///
		 (mean)   right_act_perc  = right_act  /// Actors
		 (mean)   left_act_perc  = left_act  ///
		 (mean)		act_perc = act ///
		 (mean)		retirementhealth_act_perc = retirementhealth_act ///
		 , by(track)

*** Rescale to 0 - 100
	gen retirementhealth_perc2 = retirementhealth_perc * 100
	gen right_act_perc2 = right_act_perc  * 100
	gen left_act_perc2 = left_act_perc * 100	
	gen act_perc2 = left_act_perc * 100	
	gen retirementhealth_act_perc2 = left_act_perc * 100
	
*** Center level 2 variables at their grand mean
	center retirementhealth_perc2 right_act_perc2 left_act_perc2 act_perc2 retirementhealth_act_perc2

	
*** Save data set
	save "medien_aggr.dta", replace
